package com.huluobo.a2308douyindemo.search

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.appcompat.widget.SearchView.OnQueryTextListener
import com.huluobo.a2308douyindemo.R
import com.huluobo.a2308douyindemo.databinding.ActivitySearchBinding
import com.huluobo.a2308douyindemo.mvvm.BaseActivity
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class SearchActivity : BaseActivity<ActivitySearchBinding, SearchViewModel>() {
    override fun initData() {

    }

    override fun initView() {
        binding.searchSv.setOnQueryTextListener(object : OnQueryTextListener {
            //点击确认后触发
            override fun onQueryTextSubmit(query: String?): Boolean {
                if (!query.isNullOrEmpty()) {
                    //解决搜索的key请求2次的问题,每次输入之后,会清空输入框
                    //TODO 发起搜索请求
                    binding.searchSv.isIconified = true
                }
                return true
            }

            override fun onQueryTextChange(newText: String?): Boolean {
                Log.e("TagA", "newText:$newText")
                return false
            }
        })
    }
}